安装Python

安装Python依赖

1
2
# CentOS7
yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite sqlite-devel bzip2-devel curl wget ncurses-devel sqlite-devel gdbm-devel xz-devel tk-devel

安装pyenv

1
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

配置bash_profile

1
2
3
4
5
6
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc

exec "$SHELL"

安装Python

1
2
3
4
5
pyenv install 3.6.5 -v

pyenv global 3.6.5

pyenv rehash

/root/.pyenv/versions/3.6.5/bin/python

1
pip install virtualenvwrapper pipenv
1
2
3
4
5
6
7
vim ~/.bashrc

#start virtualwrapper
VIRTUALENVWRAPPER_PYTHON=/root/.pyenv/versions/3.6.5/bin/python
export WORKON_HOME='~/.virtualenv'
source /root/.pyenv/versions/3.6.5/bin/virtualenvwrapper.sh
#end

pipenv –python=/root/.pyenv/versions/3.6.5/bin/python

因Supervisor现在不支持python3的版本需要安装Python 2.7.14

pyenv install 2.7.14 -v
pyenv global 2.7.14
pyenv rehash

更改pypi源

1
2
3
4
5
6
7
# 新建pip.conf存放目录
mkdir ~/.pip&&cd ~/.pip

cat >pip.conf<<EOF
[global]
index-url = https://pypi.douban.com/simple
EOF

安装Supervisor Supervisor使用简介

新建虚拟环境

1
2
cd /usr/local/
mkdir py2 py3
1
2
3
4
cd /usr/local/py2
pipenv --python=/root/.pyenv/versions/2.7.14/bin/python

workon py2
1
pyenv virtualenv 2.7.13 supervisor

激活虚拟环境

1
source /root/.pyenv/versions/2.7.13/envs/supervisor/bin/activate

安装supervisor

1
pip install supervisor
1
2
3
mkdir -p /etc/supervisor/

echo_supervisord_conf > /etc/supervisord.conf
1
echo_supervisord_conf > /etc/supervisor/supervisord.conf
1
2
3
4
vim /etc/supervisord.conf

[include]
files = /etc/supervisor/conf.d/*.conf
1
/root/.virtualenv/py2-kYuLH55n/bin/supervisord -c /etc/supervisord.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vim /usr/lib/systemd/system/supervisord.service

[Unit]
Description=supervisord - Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target

[Service]
Type=forking
ExecStart=/root/.virtualenv/py2-kYuLH55n/bin/supervisord -c /etc/supervisord.conf
ExecReload=/root/.virtualenv/py2-kYuLH55n/bin/supervisorctl reload
ExecStop=/root/.virtualenv/py2-kYuLH55n/bin/supervisorctl shutdown

[Install]
WantedBy=multi-user.target

启动supervisor

1
2
3
4
5
6
7
8
9
# 查看进程
ps aux | grep supervisord

systemctl daemon-reload
systemctl enable supervisord
systemctl start supervisord
systemctl status supervisord -l
systemctl stop supervisord
systemctl reload supervisord

Scrapyd

新建虚拟环境

1
2
3
4
cd /usr/local/py3
pipenv --python=/root/.pyenv/versions/3.6.5/bin/python

workon py3-hv-Nhry6
1
2
3
4
5
6
7
pyenv virtualenv 3.6.2 scrapyd

source /root/.pyenv/versions/3.6.2/envs/scrapyd/bin/activate

pyenv activate scrapyd

pyenv deactivate

安装scrapyd

1
pip install scrapyd

mkdir -p /data/scrapyd

配置scrapyd

/etc/supervisor/scrapyd.conf

1
2
3
4
5
6
7
8
9
cat >/etc/supervisor/scrapyd.conf<<EOF
[program:scrapyd]
command=workon py3-hv-Nhry6
directory=/data/scrapyd
command=/root/.virtualenv/py3-hv-Nhry6/bin/scrapyd
autostart=true
autorestart=true
redirect_stderr=true
EOF

重启supervisor

1
2
3
4
5
/root/.virtualenv/py2-kYuLH55n/bin/supervisorctl

status

reread|reload

安装SipderKeeper

安装

1
2
3
source /root/.pyenv/versions/3.6.2/envs/scrapyd/bin/activate

pip install spiderkeeper

mkdir -p /data/spiderkeeper

配置spiderkeeper

/etc/supervisor/spiderkeeper.conf

1
2
3
4
5
6
7
8
9
cat >/etc/supervisor/spiderkeeper.conf<<EOF
[program:spiderkeeper]
command=source /root/.pyenv/versions/3.6.2/envs/scrapyd/bin/activate
directory=/data/spiderkeeper
command=/root/.virtualenv/py3-hv-Nhry6/bin/spiderkeeper --port=8000 --server=http://localhost:6800 --username=admin --password=admin
autostart=true
autorestart=true
startretries=3
EOF

重启supervisor

1
2
3
4
5
/root/.pyenv/versions/supervisor/bin/supervisorctl

status

reread|reload

###

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. 安装Python
    1. 1.1. 安装Python依赖
    2. 1.2. 安装pyenv
      1. 1.2.1. 配置bash_profile
      2. 1.2.2. 安装Python
    3. 1.3. 更改pypi源
  2. 2. 安装Supervisor Supervisor使用简介
    1. 2.1. 新建虚拟环境
    2. 2.2. 激活虚拟环境
    3. 2.3. 安装supervisor
    4. 2.4. 启动supervisor
  3. 3. Scrapyd
    1. 3.1. 新建虚拟环境
    2. 3.2. 安装scrapyd
    3. 3.3. 配置scrapyd
    4. 3.4. 重启supervisor
  4. 4. 安装SipderKeeper
    1. 4.1. 安装
    2. 4.2. 配置spiderkeeper
    3. 4.3. 重启supervisor
,